﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using KP_CommonLibrary.KP_DataAccess;

namespace KP_CommonLibrary.KP_Business
{
    public class KP_BLListBase:KP_IBLL
    {
        protected  KP_DataAccess.KP_DALListBase DataAccess { get; set; }

        public KP_BLListBase()
        {
        }
        public KP_BLListBase(string tableName)
        {
            DataAccess = new KP_DataAccess.KP_DALListBase(tableName);
        }
        public virtual void Insert(DataRow item)
        {
            if (!DataAccess.Insert(null, item))
                throw new Exception("Không có bản ghi nào được thêm mới");
        }
        public String DataTable
        {
            get { return DataAccess.TableName; }
        }
        public virtual void Update(DataRow item)
        {
            if (!DataAccess.Update(null, item))
                throw new Exception("Không có bản ghi nào được cập nhật");
        }
        public virtual void Delete(DataRow item)
        {
            if (!DataAccess.Delete(null, item))
                throw new Exception("Không có bản ghi nào bị xóa bỏ");
        }
        public virtual void Fill(DataSet ds, string whereCondition, bool clearBeforeFille, params string[] fields)
        {
            DataAccess.Fill(ds, whereCondition, clearBeforeFille, fields);
        }
        public virtual void Fill(DataTable tblData,string whereCondition, bool clearBeforeFille,params string[] fields)
        {
            DataAccess.Fill(tblData, whereCondition, clearBeforeFille, fields);
        }
        public virtual DataTable Select(string whereCondition, params string[] fields)
        {
            return DataAccess.Select(whereCondition,"", fields);
        }
        public virtual DataTable Select()
        {
            return DataAccess.Select();
        }
        public DataTable GetSchema()
        {
            return GetSchema(DataAccess.TableName);
        }

        public static DataTable GetSchema(string tableName)
        {
            return KP_DataAccess.KP_DALListBase.GetSchemaTable(tableName);
        }
    }
}
